package com.mission.shaco.warehouse;

import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.mission.shaco.warehouse.models.ClientConfig;
import com.mission.shaco.warehouse.models.Roles;
import com.mission.shaco.warehouse.models.Tool;

import org.json.JSONArray;
import org.json.JSONException;

public class BasicActivity extends AppCompatActivity {

	String configFile = "data.dat";
	String configPath;
	Roles role;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		configPath = Environment.getExternalStorageDirectory().toString();

	}

	public String getConfigPath(){
		return this.configPath+"/"+this.configFile;
	}

	public void noticeMessage(String message){
		Toast.makeText(this , message, Toast.LENGTH_SHORT ).show();
	}

	public String getOpreateName(){
		role = this.getRole();
		return role != null ? this.getRole().getRealName() : "";
    }

    public Roles getRole(){
		if(this.role == null) {
			this.role = new Tool().getObjectFromString("role", Roles.class);
		}
		return this.role;
	}


	public JSONArray getRoles() throws JSONException {
		return this.getRole().getRoleList();
	}



	public static void setEditTextReadOnly(TextView view){
		view.setTextColor(R.color.readOnlyColor);   //设置只读时的文字颜色
		if (view instanceof android.widget.EditText){
			view.setCursorVisible(false);      //设置输入框中的光标不可见
			view.setFocusable(false);           //无焦点
			view.setFocusableInTouchMode(false);     //触摸时也得不到焦点
		}
	}

}
